import { SearchHistory, Suggestion } from '@/types/data'
import { SearchAction } from '@/types/store'

type SearchState = {
   suggestion:Suggestion,
   histories:SearchHistory,

}
const initState:SearchState = {
  suggestion: [],
  histories: [] // 初始搜索关键字,

}

const Search = (state = initState, action:SearchAction):SearchState => {
  if (action.type === 'search/suggestion') {
    return { ...state, suggestion: action.payload }
  } else if (action.type === 'search/history') {
    return { ...state, histories: action.payload }
  } else if (action.type === 'search/clearHistories') {
    return { ...state, histories: [] }
  }
  return state
}
export default Search
